package com.icss.dao;

import com.icss.domian.IllegalItem;
import com.icss.domian.QueryVO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

public interface IllegalDao extends JpaRepository<IllegalItem,Integer>, JpaSpecificationExecutor<IllegalItem> {

    @Modifying
    @Transactional
    @Query(value = " select i.illegal_item_id as illegalItemId , i.illegal_item_code as illegalItemCode," +
            "i.illegal_item_name as  illegalItemName , i.illegal_item_fine as illegalItemFine ," +
            " i.illegal_item_score as  illegalItemScore  , i.get_illegal_item_count as getIllegalItemCount  from t_illegal_item as i " , nativeQuery = true)
     List<QueryVO> findAllIllegalItem();

    @Modifying
    @Transactional
    @Query(value = " select i.illegal_item_id as illegalItemId , i.illegal_item_code as illegalItemCode , " +
            "i.illegal_item_name as  illegalItemName , i.illegal_item_fine as illegalItemFine ," +
            " i.illegal_item_score as  illegalItemScore from t_illegal_item as i where illegal_item_code = ?1 " , nativeQuery = true)
    List<QueryVO> findIllegalItemById(String illegalItemCode);


    @Modifying
    @Transactional
    @Query(value = "update t_illegal_item  set get_illegal_item_count=get_illegal_item_count + 1" +
            " where illegal_item_code= ?1 ",nativeQuery = true)
    void updateIllegalItemCount(String illegalItemCode);
}
